package shuai1.inter;

import java.util.Date;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import shuai1.action.InterceptorAction;

public class MyInterceptor extends AbstractInterceptor {

	private int sleep;
	public String intercept(ActionInvocation invocation) throws Exception {
		//输出执行当前时间
		System.out.println("开始执行Action时间"+(new Date()).toLocaleString());
		//得到被拦截的Action实例
		InterceptorAction action=(InterceptorAction) invocation.getAction();
		action.setSleep(sleep);
		//执行Action的execute方法
		String result=invocation.invoke();
		//输出执行后当前时间
		System.out.println("执行完Action时间"+(new Date()).toLocaleString());
		//返回拦截的Action的逻辑视图
		return result;
	}
	public int getSleep() {
		return sleep;
	}
	public void setSleep(int sleep) {
		this.sleep = sleep;
	}
	
}
